package com.jian.java.one;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @author Jiange
 * @create 2021-09-21-9:15
 */
public class Producer {
    public static final String QUEUE_NAME = "hello";
    public static void main(String[] args) throws IOException, TimeoutException {
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("127.0.0.1");
        factory.setUsername("admin");
        factory.setPassword("123456");
        Connection connection = factory.newConnection();

        Channel channel = connection.createChannel();
        //第二个参数表示是否持久true表示持久   第三个参数表示这个队列是否只供一个消费者消费  true表示可以消息共享, 第四个表示最后一个消费者离开队列以后是否自动删除 true表示删除
        channel.queueDeclare(QUEUE_NAME,false,false,false,null);

        String message = "你好";

        //1.exchange   2.队列名  3.其他参数  4. 消息体
        channel.basicPublish("","",null,message.getBytes());
    }
}
